package com.stylefeng.guns.modular.apple_sign_task_manage.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.apple.properties.SftpProperties;
import com.stylefeng.guns.modular.apple_sign_task_manage.bo.MerchantNameBO;
import com.stylefeng.guns.modular.system.model.User;
import com.stylefeng.guns.modular.system.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.apple_sign_task_manage.service.ISignTasksService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 签包任务管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-20 14:54:15
 */
@Controller
@RequestMapping("/signTasks")
public class SignTasksController extends BaseController {

    private String PREFIX = "/apple_sign_task_manage/signTasks/";

    @Resource
    private ISignTasksService signTasksService;

    @Resource
    private IUserService userService;

    /**
     * 跳转到签包任务管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "signTasks.html";
    }

    /**
     * 获取签包任务管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(value = "sortValue",defaultValue = "1") String sortValue,
                       @RequestParam(value = "merchantName",defaultValue = "0") Integer merchantName,
                        @RequestParam(value = "page",defaultValue = "0") Integer page,
                       @RequestParam(value = "limit",defaultValue = "20") Integer limit,
                       @RequestParam(value = "status",required = false) Integer status,
                       @RequestParam(value = "signBeginTime",required = false) String signBeginTime,
                       @RequestParam(value = "signEndTime",required = false) String signEndTime) {
        return signTasksService.listSignTask(sortValue,merchantName,page,limit,status,signBeginTime,signEndTime);
    }

    /**
     * 获取用户下的应用所安装设备信息
     * @return
     */
    @RequestMapping(value = "/deviceInfo")
    @ResponseBody
    public Object getDeviceInfoOfApp(@RequestParam(value = "beginTime",required = false) String beginTime,
                                     @RequestParam(value = "endTime",required = false) String endTime) {
        return signTasksService.deviceInfoOfApp(beginTime,endTime);
    }

    /**
     * 获取每日签包设备信息
     * @return
     */
    @RequestMapping(value = "/everyDayDeviceInfo")
    @ResponseBody
    public Object getEveryDayDeviceInfo(@RequestParam(value = "merchantId",required = false) String merchantId,
                                        @RequestParam(value = "beginTime",required = false) String beginTime,
                                        @RequestParam(value = "endTime",required = false) String endTime) {
        return signTasksService.getEveryDayDeviceInfo(merchantId,beginTime,endTime);
    }

    /**
     * 获取商户安装设备信息
     * @return
     */
    @RequestMapping(value = "/getMerchantDeviceInfo")
    @ResponseBody
    public Object getMerchantDeviceInfo(@RequestParam(value = "merchantId",required = false) String merchantId,
                                        @RequestParam(value = "beginTime",required = false) String beginTime,
                                        @RequestParam(value = "endTime",required = false) String endTime) {
        return signTasksService.getMerchantDeviceInfo(merchantId,beginTime,endTime);
    }

    /**
     * 商户列表
     * @return
     */
    @RequestMapping(value = "/merchantList")
    @ResponseBody
    public Object merchantList() {
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.ne("id","1");
        wrapper.ne("id","66");
        wrapper.setSqlSelect("id,name");
        List<User> userList = userService.selectList(wrapper);
        return userList.stream().map(a->{
            MerchantNameBO bo = new MerchantNameBO();
            bo.setId(a.getId());
            bo.setName(a.getName());
            return bo;
        }).collect(Collectors.toList());
    }
}
